localStorage.islogin = 0;
localStorage.dm = 0;
localStorage.mentions = 0;
localStorage.comments = 0;

function fetchWeiboFeed() {
	var xhr = new XMLHttpRequest();
	xhr.onreadystatechange = function(data) {
	  if (xhr.readyState == 4) {
		if (xhr.status == 200) {
		    var data = JSON.parse(xhr.responseText);
			localStorage.islogin = 1;
			localStorage.dm = data['dm'];
			localStorage.mentions = data['mentions'];
			localStorage.comments = data['comments'];
		    var n = data['dm'] + data['mentions'] + data['comments'];
		  newmsg(n);
		} else {
			localStorage.islogin = 0;
		    waring();
		}
	  }
	}
	var url = 'http://api.t.sina.com.cn/statuses/unread.json?source=1870891660';
	xhr.open('GET', url, true);
	xhr.send();
};

function var_dump(data){
	for(var key in data){
		alert(key+':'+data[key]);
	}
}

function bulid_post_url(title , url , pic){
	var post_weibo = 'http://service.weibo.com/share/share.php?appkey=1870891660&';
	if(title){
		title = encodeURIComponent(huati+title);
		post_weibo += 'title='+title+'&';
	}
	if(url){
		url = encodeURIComponent(url);
		post_weibo += 'url='+url+'&';
	}
	if(pic){
		pic = encodeURIComponent(pic);
		post_weibo += 'pic='+pic+'&';
	}
	return post_weibo;
}

function waring(){
	chrome.browserAction.setBadgeText({ text: '?' });
	chrome.browserAction.setTitle({title:'请登录新浪微博'});
	chrome.browserAction.setBadgeBackgroundColor({color:[255,235,56,180]});
}

function newmsg(n){
	if(n > 0){
		chrome.browserAction.setBadgeText({ text: ""+n+"" });
		chrome.browserAction.setTitle({title:'有新消息,去看看'});
	}
	else{
		chrome.browserAction.setBadgeText({ text: '' });
		chrome.browserAction.setTitle({title:'我的新浪微博'});
	}
	chrome.browserAction.setBadgeBackgroundColor({color:[255,0,0,180]});
}